package ru.st.selenium;

//import java.util.regex.Pattern;
//import java.util.concurrent.TimeUnit;

//import org.testng.*;
import org.testng.annotations.*;

import static org.junit.Assert.*;
//import static org.hamcrest.CoreMatchers.*;

//import org.openqa.selenium.*;
//import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.support.ui.ExpectedConditions;
//import org.openqa.selenium.support.ui.Select;

import ru.st.selenium.model.User;

public class Login extends ru.st.selenium.pages.TestBase {

//  @Test
//  public void testLogin() throws Exception {
//	driver.get(baseUrl + "/php4dvd/");
//    WebElement usernameField = driver.findElement(By.id("username"));
//	usernameField.clear();
//    usernameField.sendKeys("admin");
//	WebElement passwordField = driver.findElement(By.name("password"));
//	passwordField.clear();
//    passwordField.sendKeys("admin");
//    driver.findElement(By.name("submit")).click();
//    //Wait MainMenu element
//    WebElement MainMenu = wait.until(ExpectedConditions
//    		.presenceOfElementLocated(By.cssSelector(".center>nav")));    
//  }
	
  @BeforeMethod
  public void mayBeLogout() {
    if (app.getUserHelper().isLoggedIn()) {
      app.getUserHelper().logout();
    }
  }
	  
  @Test
  public void testLoginOK() throws Exception {
    User user = new User().setLogin("admin").setPassword("admin");
    app.getUserHelper().loginAs(user);
    assertTrue(app.getUserHelper().isLoggedInAs(user));
  }

  @Test
  public void testLoginFailed() throws Exception {
    User user = new User().setLogin("admin").setPassword("wrong");
    app.getUserHelper().loginAs(user);
    // assertFalse(app.getUserHelper().isLoggedIn());
    assertTrue(app.getUserHelper().isNotLoggedIn());
  }	
	
}
